package com.cysion.study.ui.personal

import android.os.Bundle
import android.view.View
import android.widget.EditText
import android.widget.TextView
import com.cysion.study.ktbox.base.BaseActivity
import com.cysion.study.ktbox.utils.whiteTextTheme
import com.cysion.other.color
import com.cysion.other.startActivity_ex
import com.cysion.study.uibox.bar.TopBar
import com.cysion.study.uibox.dialog.Alert
import com.cysion.study.R
import com.cysion.study.constant.BUNDLE_KEY
import com.cysion.study.helper.UserCache
import com.cysion.study.ktbox.Box
import com.cysion.study.ktbox.utils.ACache
import com.cysion.study.ui.login.ForgetPwdActivity
import com.cysion.study.ui.login.LoginActivity
import com.cysion.study.widget.ShowToast
import kotlinx.android.synthetic.main.activity_setting_pwd.*

/**
 * Created by chu on 2019-07-01.
 */
class SettingPwdActivity:BaseActivity(), View.OnClickListener {


    override fun getLayoutId(): Int = R.layout.activity_setting_pwd

    override fun initView() {
        whiteTextTheme(color(R.color.main_cl))
        topbar.apply {
            setTitle("密码管理")
            setOnTopBarClickListener { obj, pos ->
                if (pos == TopBar.Pos.LEFT) {
                    finish()
                }
            }
        }
        tv_set_pay.setOnClickListener(this)
        tv_modify_pwd.setOnClickListener(this)

        var teacherType = "1"//登录类型 1.普通员工 2.私教
        var ttype= ACache.get(Box.context).getAsString("teacherType")
       /* if (ttype == "0") {//普通教师首页fragment
            tv_set_pay.visibility = View.GONE
        } else {
            tv_set_pay.visibility = View.VISIBLE
        }*/

    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tv_out->{
                UserCache.clear()
                self.startActivity_ex<LoginActivity>()
                finish()
            }
            R.id.tv_set_pay->{//设置支付密码
                //pageType页面共用类型  1修改登录密码  2设置支付密码  0忘记密码
                val pageType = "2"
                var bundle = Bundle()
                bundle.putString("pageType", pageType)
                self.startActivity_ex<ForgetPwdActivity>(BUNDLE_KEY,bundle)
            }
            R.id.tv_modify_pwd->{//修改登录密码
                //pageType页面共用类型  1修改登录密码  2设置支付密码  0忘记密码
                val pageType = "1"
                var bundle = Bundle()
                bundle.putString("pageType", pageType)
                self.startActivity_ex<ForgetPwdActivity>(BUNDLE_KEY,bundle)
            }
            R.id.tv_update->{
//                updateApp()
                ShowToast("当前已是最新版本")
            }
        }

    }

    private fun updateApp() {
        val view = Alert.setup(this, R.layout.dialog_comment, 0.8f, false, null)
        val tv_title = view.findViewById<TextView>(R.id.tv_title)
        val editor = view.findViewById<EditText>(R.id.etComment)
        tv_title.setText("版本更新")
        editor.setText("这是更新内容")
        view.findViewById<TextView>(R.id.tv_cancel).setOnClickListener {
            ShowToast("下次再说")
            Alert.close()
//            clickListener?.invoke(CANCEL, "")
        }
        view.findViewById<TextView>(R.id.tv_confirm).setOnClickListener {
            ShowToast("立即更新")
            Alert.close()
//            clickListener?.invoke(CONFIRM, editor.text.toString().trim())
        }
    }

    override fun closeMvp() {
    }
}